﻿#include "circle.h"
#include "../include/dxf/dl_codes.h"

namespace Entities
{

Circle::Circle():
    m_radius(0.0),
    m_center(0.0,0.0,0.0),
    m_drawableRadius(0.0)
{

}

Circle::Circle(const Point &center,double radius)
{
    m_center=center;
    m_radius=radius;
    m_drawableRadius=0.0;
}

Circle::Circle(const Circle &circle)
{
    m_center=circle.m_center;
    m_radius=circle.m_radius;
    m_drawableRadius=circle.GetDrawableRadius();
    SetAttributes(circle.GetAttributes());
}

Circle::~Circle()
{

}
void Circle::printInfo(){
    qDebug()<<"Circle重要数据打印"<<"m_radius="<<m_radius<<"m_center点数据=";
    m_center.printInfo();
}
void Circle::Draw(QPainter& painter)
{
    QPen pen;
    QColor rgb(dxfColors[m_attributes.color][0]*255, dxfColors[m_attributes.color][1]*255, dxfColors[m_attributes.color][2]*255);
    pen.setColor(rgb);
    pen.setWidth(m_attributes.line_width);
    pen.setStyle((Qt::PenStyle)m_attributes.getLineType());
    painter.setPen(pen);
    double centerX=m_center.GetDrawableX();
    double centerY=m_center.GetDrawableY();
    QPoint point(round(centerX),round(centerY));
    int radius=round(m_drawableRadius);
    painter.drawEllipse(point,radius,radius);
}
void Circle::writeDxfInfo(DL_Dxf &dxf, DL_WriterA* dw){
    Attributes a = GetAttributes();
    printInfo();
    DL_CircleData data(m_center.GetX(), m_center.GetY(), m_center.GetZ(), m_radius);
    dxf.writeCircle(*dw, data, DL_Attributes(a.layer_name, a.color, a.line_width, a.line_type, 1.0));
}
Entity*Circle::Clone()
{
    Entity *circle=new Circle(*this);
    return circle;
}

void Circle::Transform(double*params,int size)
{
    if(size>0)
    {

        double scale=params[0];
        m_center.Transform(params,size);
        m_drawableRadius=m_radius/scale;
    }
}
void Circle::Scale(double ratio)
{
    m_center.Scale(ratio);
    m_drawableRadius*=ratio;
}

void Circle::Transfer(double dx,double dy,double dz)
{
    m_center.Transfer(dx,dy,dz);
}

void Circle::Rotate(double angle,double cx,double cy,double cz)
{

}
void Circle:: CorrectCoord(double bx,
                           double by,
                           double bz,
                           double sx,
                           double sy,
                           double sz,
                           double rotaAngle)
{
    m_center.CorrectCoord(bx,by,bz,sx,sy,sz,rotaAngle);
    m_radius*=sx;
}

}
